package ex.datastream.windows.windowFunctions;

import ex.datastream.ApiFrame;
import ex.datastream.functions.richFunction.MyProcessWindowFunction02;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.streaming.api.datastream.KeyedStream;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.datastream.WindowedStream;
import org.apache.flink.streaming.api.windowing.assigners.SlidingProcessingTimeWindows;
import org.apache.flink.streaming.api.windowing.time.Time;
import org.apache.flink.streaming.api.windowing.windows.TimeWindow;


/**
 * keyBy+window+process(ProcessWindowFunction)
 */
public class ProcessWindowFuncTest extends ApiFrame {
    public static void main(String[] args) throws Exception {
        ProcessWindowFuncTest windows=new ProcessWindowFuncTest();
        windows.getEnv();
        SingleOutputStreamOperator<Tuple2<String,Long>> outputStreamOperator =windows.getSingleOutputStreamOperator();

        KeyedStream<Tuple2<String,Long>, String> keyedStream = outputStreamOperator.keyBy(value -> value.f0);

        WindowedStream<Tuple2<String,Long>, String, TimeWindow> windowedStream =
                keyedStream.window(SlidingProcessingTimeWindows.of(Time.seconds(10),Time.seconds(5)));

        windowedStream.process(new MyProcessWindowFunction02()).print();

        windows.env.execute();
    }
}
